"use strict";
/**
 * @author zhaojiuyi
 * @date 2022/9/18-17:48
 * @version 1.0.0
 */
import store from "@/store/index"
import Index from '@/views/user/common/Index'
import login from '@/views/user/Login'
import MedicalBox from "@/views/user/MedicalBox"
import userInfo from '@/views/user/UserInfo'
import medicalEdit from '@/views/common/medicalRecordPage'
import medicalRecordPage from "@/views/common/medicalRecordPage";
const router = [
  {
    path: '/', //路由地址
    name: 'home',
    component: Index, //组件
    meta: { requiresAuth: true }, //验证
    beforeEnter: indexBeforeEnter,
    redirect: '/index',
    children:[
      {
        path:'/index',
        name: "index",
        component: MedicalBox
      },
      {
        path: '/userinfo',
        name: 'userinfo',
        component: userInfo
      },
      {
        path: '/editMedical',
        name: 'editMedical',
        component: medicalEdit
      },
      {
        path: "/recordInfo",
        name: "recordInfo",
        component: medicalRecordPage
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: login
  }
]
export const userRouter = () => {
  const path = '/user'
  // const obj = {identity:path}
  return routerSplice(path,router)
}
function routerSplice(path,routeList){
  return routeList.map(item => {
    item.path = path.concat(item.path)
    item.name = path.concat(item.name)
    if (item.children){
      item.redirect = path.concat(item.redirect)
      item.children = routerSplice(path,item.children)
    }
    return item
  })
}
function indexBeforeEnter(to, from, next) {  //独享路由守卫
  if (store.state.token && store.state.identity === 1){
    next()
  }else {
    next({path:"/user/login"})
  }
}
